<template>
	<view>
		<navbar title="编辑地址" :autoBack="true"></navbar>
		<scroll-view scroll-y="true" class="scbox">
			<view class="con">
				<view class="con__box">
					<view class="con__box__item">
						<view class="con__box__item__label">
							联系人
						</view>
						<input type="text" class="con__box__item__inp" v-model="form.username" placeholder="请输入联系人" />
					</view>
					<view class="con__box__item">
						<view class="con__box__item__label">
							联系电话
						</view>
						<input type="number" maxlength="11" class="con__box__item__inp" v-model="form.mobile" placeholder="请输入联系电话" />
					</view>
					<view class="con__box__item" @click="onPickAddress">
						<view class="con__box__item__label">
							选择地区
						</view>
						<view class="con__box__item__inp" style="color: grey;" v-if="!addr">
							省市区
						</view>
						<view class="con__box__item__inp" v-else>
							{{addr}}
						</view>
					</view>
					<view class="con__box__title">
						详细地址
					</view>
					<u--textarea v-model="form.detail" placeholder="街道门牌信息"
						placeholderStyle='color:#919191;font-size:24rpx;' border='bottom'></u--textarea>
					<view class="footer" @click="toaddr">
						<image src="/static/my/btn.png" class="btn" mode=""></image>
						<view class="footer__text">
							提交
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
		<pick-adress ref="pickAdress" @addrobj='getaddr'></pick-adress>
	</view>
</template>

<script>
	import {
		getLocal
	} from '@/api/getaddr.js'
	import pickAdress from '@/uni_modules/john-pickAddress/components/john-pickAddress/pickAddress.vue'
	import user from '@/api/_user.js'
	export default {
		components: {
			pickAdress
		},
		data() {
			return {
				form: {
					"username": "",
					"mobile": "",
					"detail": "",
					"province": "",
					"city": "",
					"area": ""
				},
				addr:''
			};
		},
		methods:{
			onPickAddress() {
				this.$refs.pickAdress.onOpen()
			},
			getaddr(obj) {
				this.form.province = obj.province
				this.form.city = obj.city
				this.form.area = obj.district
				this.addr = obj.addr
			},
			toaddr() {
				let {
					detail,
					username,
					mobile
				} = this.form
				if (!username) {
					this.$u.toast('请填写联系人')
					return
				}
				if (!mobile) {
					this.$u.toast('请填写联系电话')
					return
				}
				if (!this.addr) {
					this.$u.toast('请选择地区')
					return
				}
				if (!detail) {
					this.$u.toast('请填写详细地址')
					return
				}
				user.insertAddress(this.form).then(res => {
					// console.log(res)
					if (res.data.code == 1) {
						this.$u.toast('修改成功')
						setTimeout(()=>{
							uni.navigateBack()
						},1000)
					}
				})
			
				// console.log(this.form)
			},
		},
	}
</script>

<style lang="scss">
	page {
		background-color: #F0F3F7;
	}

	.con {
		padding: 20rpx 30rpx;

		&__box {
			padding: 16rpx 0 88rpx 30rpx;
			background-color: #fff;
			border-radius: 30rpx;

			&__title {
				font-family: PingFang SC;
				font-weight: bold;
				font-size: 30rpx;
				color: #010101;
				line-height: 30rpx;
				margin: 34rpx 0 0 3rpx;
			}

			&__item {
				display: flex;
				align-items: center;
				border-bottom: 2rpx solid #F9F9F9;
				height: 106rpx;
				padding-right: 35rpx;

				&__label {
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 26rpx;
					color: #6D6D6D;
					line-height: 26rpx;
				}

				&__inp {
					text-align: right;
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 26rpx;
					color: #030303;
					line-height: 38rpx;
					flex: 1;
				}

				&__checkbox {
					display: flex;
					align-items: center;
					justify-content: center;
					margin-right: 6rpx;
					margin-left: 70rpx;

					&__icon {
						width: 35rpx;
						height: 35rpx;
					}
				}
			}
		}
	}

	::v-deep.u-textarea {
		padding: 37rpx 0;

		.u-textarea__count {
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 24rpx;
			color: #AFAFAF;
			line-height: 24rpx;
			padding-bottom: 28rpx;
		}
	}

	::v-deep.u-border-bottom {
		border-bottom-width: 2rpx !important;
		border-color: #F9F9F9 !important;
	}

	.footer {
		position: relative;
		margin-top: 83rpx;

		.btn {
			width: 615rpx;
			height: 105rpx;
		}

		&__text {
			width: 615rpx;
			display: flex;
			justify-content: center;
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 32rpx;
			color: #3A4E6D;
			line-height: 32rpx;
			// padding-top: 33rpx;
			position: absolute;
			padding-top: 33rpx;
			top: 0;
			left: 0;
		}
	}
</style>